from selenium import webdriver
from selenium.webdriver.common.by import By
import time
import unittest


class weibo(unittest.TestCase):

    def setUp(self) -> None:
        # 打开浏览器
        self.driver = webdriver.Chrome()
        self.driver.get('https://weibo.com/')
        time.sleep(2)
        # 窗口最大化
        self.driver.maximize_window()
        self.driver.implicitly_wait(5)

    def tearDown(self) -> None:
        time.sleep(5)
        self.driver.quit()

    def test_weibo_01(self):
        # 点击登录/注册
        self.driver.find_element(By.XPATH,
                            '/html/body/div[1]/div[2]/div[2]/div[2]/main/div[2]/div/div/div[2]/div[1]/div/button').click()
        time.sleep(2)
        # 窗口切换
        self.driver.switch_to.window(self.driver.window_handles[-1])
        time.sleep(2)
        # 输入账号
        self.driver.find_element(By.XPATH, '//*[@id="app"]/div/div/div[2]/div[2]/form/div[1]/input').send_keys(
            '15985645480')
        # 强制等待 输入验证码
        time.sleep(30)
        # 点击登录按钮
        self.driver.find_element(By.XPATH, '//*[@id="app"]/div/div/div[2]/div[2]/button').click()
        time.sleep(2)
        # 窗口切换
        self.driver.switch_to.window(self.driver.window_handles[-1])
        time.sleep(2)
        # 点击头像
        self.driver.find_element(By.XPATH, '/html/body/div/div[2]/div[1]/div/div[1]/div/div/div[2]/div/div[1]/a[5]/div/div/div/div/img').click()
        time.sleep(2)
        # 断言1：验证登录成功后断言：小高大王来了
        dy1 = self.driver.find_element(By.CLASS_NAME, 'ProfileHeader_name_1KbBs').text
        self.assertEqual('小高大王来了', dy1)


if __name__ == '__main__':
    unittest.main()

